<?php

class SeoUrlAction extends CAction {
    public function run() {
        $id = Yii::app()->request->getParam('id');
        $slug = Yii::app()->request->getParam('slug');
        $meme = Meme::model()->findByPk($id);
        if($meme) {
        	$seoName = Utility::seoName($meme->title);
        	if($seoName != $slug) {
        		$url = Yii::app()->createAbsoluteUrl('site/seo_url', array('id' => $meme->meme_id, 'slug' => $seoName));
        		Yii::app()->request->redirect($url, true, 301);
        	}
        	else {
        		Yii::app()->controller->forward('site/index');
        	}
        }
    }
}